const db = require('../utils/db.js'); 

const getData = ( sql, ctx ) => {
    return new Promise( ( resolve, reject ) => {
        return db.query( sql, ( err, data ) => {
            if( err ) {
                ctx.body = {
                    code: 0,
                    error: '数据库出错，请再次尝试'
                }
            }else {
                ctx.body = {
                    code: 1,
                    results: data
                }
            }

            resolve( ctx )
        } )
    } )
}

module.exports = getData
